package com.study.scheduled.thread;

import com.study.scheduled.config.OpcParams;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 外部线程
 */
public class PublicThread implements Runnable {
    // 线程池
    private ExecutorService pool;
    // 接口信息
    private List<OpcParams.Interfaces> interfaces = new ArrayList<>();

    public PublicThread(Integer taskSize, List<OpcParams.Interfaces> interfaces){
        this.pool = Executors.newFixedThreadPool(taskSize);
        this.interfaces = interfaces;
    }

    @Override
    public void run() {
        if(interfaces != null && interfaces.size() > 0){
            for(OpcParams.Interfaces i : interfaces){
                SonTread sonTread = new SonTread(i.getName(), i.getUrl(), i.getParams());
                // 线程池开始执行线程
                pool.submit(sonTread);
            }
        }
    }
}
